import { Request, Response, NextFunction } from 'express';
import { validationResult } from 'express-validator';

// 验证请求参数中间件
export const validateRequest = (
  req: Request,
  res: Response,
  next: NextFunction
): void => {
  const errors = validationResult(req);
  
  if (!errors.isEmpty()) {
    const errorMessages = errors.array().map(error => error.msg);
    res.status(400).json({
      success: false,
      code: 4000,
      message: errorMessages.join(', '),
      errors: errors.array(),
      timestamp: new Date().toISOString()
    });
    return;
  }
  
  next();
}; 